import Singleton from '../Base/Singleton'
import { resources, SpriteFrame } from 'cc'

// 统一资源的导入
//泛型单例模式，单例模式一个类只有一个实例并提供全局访问点
export default class ResourceManager extends Singleton {
  static get Instance() {
    return super.GetInstance<ResourceManager>()
  }
  //统一资源加载的方法，外部传入路径'texture/tile/tile'和类型默认给SpriteFrame
  loadDir(path: string, type: typeof SpriteFrame = SpriteFrame) {
    return new Promise<SpriteFrame[]>((resolve, reject) => {
      resources.loadDir(path, type, (err, assets) => {
        if (err) {
          reject(err)
          return
        }

        resolve(assets)
      })
    })
  }
}
